"""
项目配置设置
"""

import os
from dataclasses import dataclass
from typing import Optional


@dataclass
class Config:
    """项目配置类"""
    # API Keys
    openai_api_key: Optional[str] = None
    deepseek_api_key: Optional[str] = None
    deepseek_base_url: str = "https://api.deepseek.com"

    # MCP 配置
    mcp_server_port: int = 3000

    # TAPD 配置
    tapd_base_url: str = "https://www.tapd.cn"

    # 输出配置
    output_dir: str = "output"

    def __post_init__(self):
        """后初始化验证"""
        if not self.deepseek_api_key:
            raise ValueError("DEEPSEEK_API_KEY 环境变量未设置")


def load_config() -> Config:
    """加载配置"""
    return Config(
        openai_api_key=os.getenv("OPENAI_API_KEY"),
        deepseek_api_key=os.getenv("DEEPSEEK_API_KEY"),
        deepseek_base_url=os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com"),
        mcp_server_port=int(os.getenv("MCP_SERVER_PORT", "3000")),
        output_dir=os.getenv("OUTPUT_DIR", "output")
    )